package com.api.gbhg.huangwm.web;

import com.engine.common.util.ParamUtil;
import weaver.conn.RecordSet;
import weaver.general.GCONST;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;
@Path("/gb/controlSwitchV2")
public class ContronSwitch {

    @GET
    @Path("/selectControlSwitchData")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> Getyggwk(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apiResult = new HashMap<String, Object>();
        apiResult.put("code","200");
        apiResult.put("msg","");
        Map<String, Object> result = Switch();
        apiResult.put("data",result);
        return apiResult;
    }


    @POST
    @Path("/updateControlSwitchData")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> updateControlSwitchData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apiResult = new HashMap<String, Object>();
        try {
            Map<String, Object> requestParams = ParamUtil.request2Map(request);
            String sfyxysdz = requestParams.get("sfyxysdz").toString();
            String sfyxkldz = requestParams.get("sfyxkldz").toString();
            String kdzkssj = requestParams.get("kdzkssj").toString();
            String kdzjssj = requestParams.get("kdzjssj").toString();
            String sfkqysbz = requestParams.get("sfkqysbz").toString();
            RecordSet rs = new RecordSet();
            rs.execute("update uf_gnkg set sfyxysdz='"+sfyxysdz+"',sfyxkldz='"+sfyxkldz+"',kdzkssj='"+kdzkssj+"',kdzjssj='"+kdzjssj+"',sfkqysbz='"+sfkqysbz+"'");

            apiResult.put("code","200");
            apiResult.put("msg","");
        }catch (Exception e){
            e.printStackTrace();
            apiResult.put("code","500");
            apiResult.put("msg",e.getMessage());
        }

        return apiResult;
    }

    public static Map<String, Object> Switch() {
        RecordSet rs = new RecordSet();
        String sql = "select sfyxysdz,sfyxkldz,kdzkssj,kdzjssj,sfkqysbz from uf_gnkg";
        rs.executeQuery(sql);
        Map<String, Object> map = new HashMap<>();
        if (rs.next()) {
            map.put("sfyxysdz", rs.getString("sfyxysdz")); //是否允预算调整
            map.put("sfyxkldz", rs.getString("sfyxkldz")); //是否允许跨类调整
            map.put("kdzkssj", rs.getString("kdzkssj"));   //可调整开始时间
            map.put("kdzjssj", rs.getString("kdzjssj"));   //可调整结束时间
            map.put("sfkqysbz",rs.getString("sfkqysbz"));   //是否开启预算编制
        }
        return map;
    }

    public static void main(String[] args) throws Exception {
        String rootPath = "D:\\WEAVER\\ecology\\";
        GCONST.setRootPath(rootPath);
        GCONST.setServerName("ecology");

        String sfyxysdz = "1";
        String sfyxkldz = "1";
        String kdzkssj = "2023-01-01";
        String kdzjssj = "2026-01-01";
        String sfkqysbz = "1";
//        RecordSet rs = new RecordSet();
//        rs.execute("update uf_gnkg set sfyxysdz='"+sfyxysdz+"',sfyxkldz='"+sfyxkldz+"',kdzkssj='"+kdzkssj+"',kdzjssj='"+kdzjssj+"',sfkqysbz='"+sfkqysbz+"'");

        System.err.println("select * from formtable_main_319 m left join hrmResource e on m.a = e.id  left join workflow_requestbase w on w.requestid=m.requestid  where" +
                "  m.requestId in(123) ");
    }
}
